<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 500px;
            height: 500px;
            background-color: #bfa;
            overflow:scroll;
        }
        .box2{
            width: 900px;
            height: 800px;
            background-color: orange;
        }
    </style>
    <script>
        window.onload = function(){
            var box1 = document.getElementsByClassName("box1")[0];
            var box2 = document.getElementsByClassName("box2")[0];
            var btn = document.getElementById("btn");
            btn.onclick = function(){
                // scrollWidth和scrollHeight可以获取元素整个滚动区域的宽度和高度
                // alert(box2.scrollWidth);
                // scrollLeft可以获取滚动条水平移动的距离
                alert(box1.scrollLeft);
                // scrollTop可以获取滚动条垂直移动的距离
                alert(box1.scrollTop);
            }
        }      
    </script>
</head>
<body>
    <div class="box1">
        <div class="box2"></div>
    </div>
    <button id="btn">确定</button>
</body>
</html>